import java.sql.*;

public class DBManager {
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    private static final String URL = "jdbc:mysql://39.105.159.64:3306/zhaoziyan";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "123";
    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName(DRIVER);
            conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static void main(String[] args) {
        Connection connection = DBManager.getConnection();
        System.out.println(connection);
        String sql = "select *from book";
        String sql2 = "select *from book";
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();

            while (resultSet.next()) { // 遍历结果集
                int id = resultSet.getInt("id"); // 假设 book 表有一个 id 列
                String bookName = resultSet.getString("bookName"); // 假设 book 表有一个 title 列
                String author = resultSet.getString("author"); // 假设 book 表有一个 author 列
                // 你可以继续获取其他列的值
                // 打印获取的数据
                System.out.println("ID: " + id + ", bookName: " + bookName + ", Author: " + author);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
